Allow configuring the column type with ToJson()#36478
Merged
AndriySvyryd merged 1 commit intomainfrom Aug 1, 2025
Merged
Conversation
Map the discriminator property to $type in JSON by default
There was a problem hiding this comment.
Pull Request Overview
This PR enables configuring column types for JSON columns when using ToJson() with complex properties and collections. It also implements the default mapping of discriminator properties to the "$type" JSON property name.
- Adds HasColumnType() method support for complex properties and collections mapped to JSON
- Maps discriminator properties to "$type" JSON property name by default
- Consolidates container column functionality from separate entity/complex type extensions into a unified TypeBase extension
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs | Adds unified container column name/type methods for all type bases |
| src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs | Updates default JSON property name to use "$type" for discriminator properties |
| src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs | Removes container column methods (moved to TypeBase) |
| src/EFCore.Relational/Extensions/RelationalComplexTypeExtensions.cs | File deleted (functionality moved to TypeBase) |
| src/EFCore.Relational/Extensions/RelationalComplexPropertyBuilderExtensions.cs | Adds HasColumnType() method for complex properties |
| src/EFCore.Relational/Extensions/RelationalComplexCollectionBuilderExtensions.cs | Adds HasColumnType() method for complex collections |
| test/EFCore.Relational.Tests/TestUtilities/TestRelationalTypeMappingSource.cs | Adds test JSON mapping support |
| test/EFCore.Relational.Tests/RelationalApiConsistencyTest.cs | Updates API consistency test references |
| test/EFCore.Relational.Tests/Metadata/RelationalModelTest.cs | Adds tests for container column type functionality |
| test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalTestModelBuilderExtensions.cs | Adds test builder extensions for HasColumnType() |
| test/EFCore.Relational.Specification.Tests/ModelBuilding/RelationalModelBuilderTest.cs | Adds comprehensive tests for new functionality |
Comments suppressed due to low confidence (1)
src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs:419
- The variable name 'columnName' is misleading since it represents a column type, not a column name. It should be renamed to 'columnType' for clarity.
=> typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)?.Value is string columnName
cincuranet
approved these changes
Aug 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Map the discriminator property to $type in JSON by default
Fixes #31252
cc @artl93